﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace AdvancedStandingAndScholarship
{
    public partial class SearchStudent : Page
    {
        public SearchStudent()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs 
e)
        {

        }
        private void btnBack_search_MouseLeftButtonDown(object 
sender, MouseButtonEventArgs e)
        {

            // TODO: Add event handler implementation here.
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
            else
            {

                NavigationService.Navigate(new Uri
("/AddPageSelectSchool", UriKind.Relative));
            }

        }

        private void btnSearch_Click(object sender, 
System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            if (cbx_searchCriteria.SelectedValue != null)
            {
                if (tbxSearchSpecify.Text.Trim() != "")
                {
                    String searchSpecify = 
tbxSearchSpecify.Text.Trim();
                    String searchCriteria = 
cbx_searchCriteria.SelectedValue.ToString();

                    ASASService.ASASServiceClient client = new 
ASASService.ASASServiceClient();
                    client.searchStudentCompleted += new 
EventHandler<ASASService.searchStudentCompletedEventArgs>
(client_searchStudentCompleted);
                    client.searchStudentAsync(searchCriteria, 
searchSpecify);
                }
                else
                {
                    MessageBox.Show("Please specify a search key 
word");
                }
            }
            else
            {
                MessageBox.Show("Please select a search criteria");
            }
        }


        void client_searchStudentCompleted(object sender, 
ASASService.searchStudentCompletedEventArgs e)
        {
            if (e.Error == null & e.Result != null)
            {
                datagrid.ItemsSource = (List<ASASService.Student>)
e.Result;
            }
        }

        private void cbx_delete_Click(object sender, 
System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
        }


    }
}
